<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据库表关系图</title>
    <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <style>
        :root {
            --primary-color: #3498db;
            --secondary-color: #2c3e50;
            --accent-color: #1abc9c;
            --light-bg: #f8f9fa;
            --card-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            background-color: var(--light-bg);
            padding-top: 20px;
            padding-bottom: 40px;
        }
        
        .container {
            max-width: 1280px;
        }
        
        .header {
            text-align: center;
            margin-bottom: 30px;
            padding: 20px;
            background: linear-gradient(to right, var(--primary-color), var(--accent-color));
            color: white;
            border-radius: 8px;
            box-shadow: var(--card-shadow);
        }
        
        h1 {
            font-weight: 600;
            margin-bottom: 10px;
        }
        
        h2 {
            color: var(--secondary-color);
            border-left: 5px solid var(--primary-color);
            padding-left: 15px;
            margin: 30px 0 20px;
            font-weight: 600;
        }
        
        .card {
            margin-bottom: 30px;
            border: none;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: var(--card-shadow);
        }
        
        .card-header {
            background-color: var(--secondary-color);
            color: white;
            font-weight: 600;
            padding: 12px 20px;
        }
        
        .card-body {
            padding: 20px;
            background-color: white;
        }
        
        .mermaid {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        
        .description {
            background-color: #f1f8fe;
            padding: 15px;
            border-radius: 5px;
            margin: 20px 0;
            border-left: 4px solid var(--primary-color);
        }
        
        .table-info {
            margin: 20px 0;
        }
        
        .table-info h4 {
            color: var(--secondary-color);
            margin-bottom: 10px;
            font-size: 1.1rem;
            font-weight: 600;
        }
        
        .table {
            font-size: 14px;
        }
        
        .table thead {
            background-color: #eef5ff;
        }
        
        .navigation {
            position: fixed;
            top: 20px;
            right: 20px;
            background-color: white;
            border-radius: 8px;
            padding: 10px;
            box-shadow: var(--card-shadow);
            z-index: 1000;
            max-width: 200px;
            max-height: 400px;
            overflow-y: auto;
        }
        
        .navigation h5 {
            color: var(--secondary-color);
            border-bottom: 2px solid var(--primary-color);
            padding-bottom: 5px;
            margin-bottom: 10px;
        }
        
        .navigation ul {
            list-style-type: none;
            padding-left: 5px;
        }
        
        .navigation li {
            margin-bottom: 8px;
        }
        
        .navigation a {
            color: var(--secondary-color);
            text-decoration: none;
            font-size: 14px;
            display: block;
            padding: 3px 5px;
        }
        
        .navigation a:hover {
            background-color: #eef5ff;
            border-radius: 3px;
        }
        
        .footer {
            text-align: center;
            padding: 20px;
            margin-top: 30px;
            background-color: var(--secondary-color);
            color: white;
            border-radius: 8px;
        }
        
        @media (max-width: 768px) {
            .navigation {
                position: static;
                margin-bottom: 20px;
                max-width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>数据库表关系图</h1>
            <p>Hello-Cloud 系统数据库设计文档</p>
        </div>
        
        <div class="navigation">
            <h5>导航</h5>
            <ul>
                <li><a href="#system-core">系统核心表</a></li>
                <li><a href="#dict-config">字典和配置表</a></li>
                <li><a href="#log-monitor">日志和监控表</a></li>
                <li><a href="#gen-code">代码生成表</a></li>
                <li><a href="#business-rel">主要业务关系</a></li>
            </ul>
        </div>
        
        <div class="card" id="system-core">
            <div class="card-header">系统核心表关系</div>
            <div class="card-body">
                <div class="description">
                    <p>系统核心表主要描述了用户、角色、部门、菜单等基础数据之间的关系。这些表构成了权限管理系统的基础，通过多对多关系实现了用户-角色-权限的灵活分配。</p>
                </div>
                
                <div class="mermaid">
                    flowchart TD
                        sys_dept --> |包含| sys_user
                        sys_dept --> |关联| sys_role_dept
                        sys_role --> |关联| sys_role_dept
                        sys_role --> |拥有权限| sys_role_menu
                        sys_role --> |分配给| sys_user_role
                        sys_menu --> |被授权给| sys_role_menu
                        sys_user --> |拥有角色| sys_user_role
                        sys_user --> |拥有岗位| sys_user_post
                        sys_post --> |分配给| sys_user_post
                        
                        subgraph 部门表
                        dept[sys_dept<br>PK: dept_id<br>parent_id<br>ancestors<br>dept_name]
                        end
                        
                        subgraph 用户表
                        user[sys_user<br>PK: user_id<br>FK: dept_id<br>user_name<br>password]
                        end
                        
                        subgraph 角色表
                        role[sys_role<br>PK: role_id<br>role_name<br>role_key]
                        end
                        
                        subgraph 菜单表
                        menu[sys_menu<br>PK: menu_id<br>menu_name<br>parent_id<br>perms]
                        end
                        
                        subgraph 岗位表
                        post[sys_post<br>PK: post_id<br>post_code<br>post_name]
                        end
                        
                        subgraph 用户角色关联表
                        user_role[sys_user_role<br>PK,FK: user_id<br>PK,FK: role_id]
                        end
                        
                        subgraph 角色菜单关联表
                        role_menu[sys_role_menu<br>PK,FK: role_id<br>PK,FK: menu_id]
                        end
                        
                        subgraph 角色部门关联表
                        role_dept[sys_role_dept<br>PK,FK: role_id<br>PK,FK: dept_id]
                        end
                        
                        subgraph 用户岗位关联表
                        user_post[sys_user_post<br>PK,FK: user_id<br>PK,FK: post_id]
                        end
                </div>
                
                <div class="table-info">
                    <h4>核心表字段说明</h4>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>字段名</th>
                                        <th>类型</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td rowspan="4">sys_dept</td>
                                        <td>dept_id</td>
                                        <td>bigint</td>
                                        <td>部门ID（主键）</td>
                                    </tr>
                                    <tr>
                                        <td>parent_id</td>
                                        <td>bigint</td>
                                        <td>父部门ID</td>
                                    </tr>
                                    <tr>
                                        <td>ancestors</td>
                                        <td>varchar</td>
                                        <td>祖级列表</td>
                                    </tr>
                                    <tr>
                                        <td>dept_name</td>
                                        <td>varchar</td>
                                        <td>部门名称</td>
                                    </tr>
                                    
                                    <tr>
                                        <td rowspan="4">sys_user</td>
                                        <td>user_id</td>
                                        <td>bigint</td>
                                        <td>用户ID（主键）</td>
                                    </tr>
                                    <tr>
                                        <td>dept_id</td>
                                        <td>bigint</td>
                                        <td>部门ID（外键）</td>
                                    </tr>
                                    <tr>
                                        <td>user_name</td>
                                        <td>varchar</td>
                                        <td>用户账号</td>
                                    </tr>
                                    <tr>
                                        <td>password</td>
                                        <td>varchar</td>
                                        <td>密码</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        
                        <div class="col-md-6">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>字段名</th>
                                        <th>类型</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td rowspan="3">sys_role</td>
                                        <td>role_id</td>
                                        <td>bigint</td>
                                        <td>角色ID（主键）</td>
                                    </tr>
                                    <tr>
                                        <td>role_name</td>
                                        <td>varchar</td>
                                        <td>角色名称</td>
                                    </tr>
                                    <tr>
                                        <td>role_key</td>
                                        <td>varchar</td>
                                        <td>角色权限字符串</td>
                                    </tr>
                                    
                                    <tr>
                                        <td rowspan="4">sys_menu</td>
                                        <td>menu_id</td>
                                        <td>bigint</td>
                                        <td>菜单ID（主键）</td>
                                    </tr>
                                    <tr>
                                        <td>menu_name</td>
                                        <td>varchar</td>
                                        <td>菜单名称</td>
                                    </tr>
                                    <tr>
                                        <td>parent_id</td>
                                        <td>bigint</td>
                                        <td>父菜单ID</td>
                                    </tr>
                                    <tr>
                                        <td>perms</td>
                                        <td>varchar</td>
                                        <td>权限标识</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="card" id="dict-config">
            <div class="card-header">字典和配置表</div>
            <div class="card-body">
                <div class="description">
                    <p>字典和配置表管理系统的配置信息和数据字典，提供了系统中各种静态数据和参数的集中管理。字典类型与字典数据构成了一对多的关系。</p>
                </div>
                
                <div class="mermaid">
                    flowchart TD
                        sys_dict_type --> |包含| sys_dict_data
                        
                        subgraph 字典类型表
                        dict_type[sys_dict_type<br>PK: dict_id<br>dict_name<br>dict_type]
                        end
                        
                        subgraph 字典数据表
                        dict_data[sys_dict_data<br>PK: dict_code<br>dict_label<br>dict_value<br>FK: dict_type]
                        end
                        
                        subgraph 参数配置表
                        config[sys_config<br>PK: config_id<br>config_name<br>config_key<br>config_value]
                        end
                </div>
                
                <div class="table-info">
                    <h4>字典和配置表字段说明</h4>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>字段名</th>
                                        <th>类型</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td rowspan="3">sys_dict_type</td>
                                        <td>dict_id</td>
                                        <td>bigint</td>
                                        <td>字典主键</td>
                                    </tr>
                                    <tr>
                                        <td>dict_name</td>
                                        <td>varchar</td>
                                        <td>字典名称</td>
                                    </tr>
                                    <tr>
                                        <td>dict_type</td>
                                        <td>varchar</td>
                                        <td>字典类型</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        
                        <div class="col-md-6">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>字段名</th>
                                        <th>类型</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td rowspan="4">sys_dict_data</td>
                                        <td>dict_code</td>
                                        <td>bigint</td>
                                        <td>字典编码</td>
                                    </tr>
                                    <tr>
                                        <td>dict_label</td>
                                        <td>varchar</td>
                                        <td>字典标签</td>
                                    </tr>
                                    <tr>
                                        <td>dict_value</td>
                                        <td>varchar</td>
                                        <td>字典键值</td>
                                    </tr>
                                    <tr>
                                        <td>dict_type</td>
                                        <td>varchar</td>
                                        <td>字典类型（外键）</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="card" id="log-monitor">
            <div class="card-header">日志和监控表</div>
            <div class="card-body">
                <div class="description">
                    <p>日志和监控表记录系统操作日志、登录日志和定时任务执行情况，为系统运行提供审计和监控能力。任务调度表与日志表构成一对多的关系。</p>
                </div>
                
                <div class="mermaid">
                    flowchart TD
                        sys_job --> |生成| sys_job_log
                        
                        subgraph 操作日志表
                        oper_log[sys_oper_log<br>PK: oper_id<br>title<br>business_type<br>oper_name]
                        end
                        
                        subgraph 登录日志表
                        logininfor[sys_logininfor<br>PK: info_id<br>user_name<br>ipaddr<br>status]
                        end
                        
                        subgraph 定时任务表
                        job[sys_job<br>PK: job_id, job_name, job_group<br>invoke_target]
                        end
                        
                        subgraph 任务日志表
                        job_log[sys_job_log<br>PK: job_log_id<br>FK: job_name, job_group<br>invoke_target]
                        end
                        
                        subgraph 通知公告表
                        notice[sys_notice<br>PK: notice_id<br>notice_title<br>notice_type<br>notice_content]
                        end
                </div>
                
                <div class="table-info">
                    <h4>日志和监控表字段说明</h4>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>字段名</th>
                                        <th>类型</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td rowspan="4">sys_oper_log</td>
                                        <td>oper_id</td>
                                        <td>bigint</td>
                                        <td>日志主键</td>
                                    </tr>
                                    <tr>
                                        <td>title</td>
                                        <td>varchar</td>
                                        <td>模块标题</td>
                                    </tr>
                                    <tr>
                                        <td>business_type</td>
                                        <td>int</td>
                                        <td>业务类型</td>
                                    </tr>
                                    <tr>
                                        <td>oper_name</td>
                                        <td>varchar</td>
                                        <td>操作人员</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        
                        <div class="col-md-6">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>字段名</th>
                                        <th>类型</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td rowspan="3">sys_job</td>
                                        <td>job_id</td>
                                        <td>bigint</td>
                                        <td>任务ID</td>
                                    </tr>
                                    <tr>
                                        <td>job_name</td>
                                        <td>varchar</td>
                                        <td>任务名称</td>
                                    </tr>
                                    <tr>
                                        <td>invoke_target</td>
                                        <td>varchar</td>
                                        <td>调用目标字符串</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="card" id="gen-code">
            <div class="card-header">代码生成表</div>
            <div class="card-body">
                <div class="description">
                    <p>代码生成表用于存储代码生成相关的业务表结构和字段信息，支持代码自动生成功能。代码生成业务表与字段表构成一对多关系。</p>
                </div>
                
                <div class="mermaid">
                    flowchart TD
                        gen_table --> |包含| gen_table_column
                        
                        subgraph 代码生成业务表
                        table[gen_table<br>PK: table_id<br>table_name<br>table_comment<br>class_name]
                        end
                        
                        subgraph 代码生成业务表字段
                        column[gen_table_column<br>PK: column_id<br>FK: table_id<br>column_name<br>column_comment]
                        end
                </div>
                
                <div class="table-info">
                    <h4>代码生成表字段说明</h4>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>字段名</th>
                                        <th>类型</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td rowspan="4">gen_table</td>
                                        <td>table_id</td>
                                        <td>bigint</td>
                                        <td>编号</td>
                                    </tr>
                                    <tr>
                                        <td>table_name</td>
                                        <td>varchar</td>
                                        <td>表名称</td>
                                    </tr>
                                    <tr>
                                        <td>table_comment</td>
                                        <td>varchar</td>
                                        <td>表描述</td>
                                    </tr>
                                    <tr>
                                        <td>class_name</td>
                                        <td>varchar</td>
                                        <td>实体类名称</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        
                        <div class="col-md-6">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>表名</th>
                                        <th>字段名</th>
                                        <th>类型</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td rowspan="4">gen_table_column</td>
                                        <td>column_id</td>
                                        <td>bigint</td>
                                        <td>编号</td>
                                    </tr>
                                    <tr>
                                        <td>table_id</td>
                                        <td>varchar</td>
                                        <td>归属表编号</td>
                                    </tr>
                                    <tr>
                                        <td>column_name</td>
                                        <td>varchar</td>
                                        <td>列名称</td>
                                    </tr>
                                    <tr>
                                        <td>column_comment</td>
                                        <td>varchar</td>
                                        <td>列描述</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="card" id="business-rel">
            <div class="card-header">主要业务关系</div>
            <div class="card-body">
                <div class="description">
                    <p>主要业务关系图展示了系统中核心实体之间的业务关联。该图从业务视角描述了用户、角色、菜单、部门等实体之间的主要交互方式。</p>
                </div>
                
                <div class="mermaid">
                    flowchart TD
                        用户 --> |拥有多个| 角色
                        用户 --> |属于一个| 部门
                        用户 --> |拥有多个| 岗位
                        角色 --> |拥有多个| 菜单权限
                        角色 --> |关联多个| 部门数据权限
                        菜单 --> |形成| 菜单树结构
                        部门 --> |形成| 部门树结构
                        字典 --> |配置| 系统参数
                        代码生成 --> |映射| 表和字段
                        任务调度 --> |执行| 系统功能
                        
                        style 用户 fill:#f9f,stroke:#333,stroke-width:2px
                        style 角色 fill:#bbf,stroke:#333,stroke-width:2px
                        style 部门 fill:#bfb,stroke:#333,stroke-width:2px
                        style 菜单权限 fill:#fbf,stroke:#333,stroke-width:2px
                </div>
                
                <div class="table-info">
                    <h4>核心业务实体说明</h4>
                    
                    <table class="table table-bordered">
                        <thead class="table-light">
                            <tr>
                                <th>业务实体</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>用户</td>
                                <td>系统的操作人员，可以关联多个角色，属于特定部门，拥有特定岗位</td>
                            </tr>
                            <tr>
                                <td>角色</td>
                                <td>权限的集合，通过角色给用户分配权限，角色可以关联到多个菜单权限和数据权限</td>
                            </tr>
                            <tr>
                                <td>部门</td>
                                <td>组织结构单元，形成树形结构，用户属于部门，部门用于数据权限控制</td>
                            </tr>
                            <tr>
                                <td>菜单</td>
                                <td>系统功能和界面的组织结构，形成树形结构，包含目录、菜单和按钮三种类型</td>
                            </tr>
                            <tr>
                                <td>岗位</td>
                                <td>用户在组织中的职位，一个用户可以有多个岗位</td>
                            </tr>
                            <tr>
                                <td>字典</td>
                                <td>系统中各类静态数据的管理，包括下拉选择、状态等</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        
        <div class="footer">
            <p>Hello-Cloud 数据库关系图 &copy; 2023</p>
        </div>
    </div>

    <script>
        // 初始化Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            securityLevel: 'loose'
        });
        
        // 平滑滚动
        document.querySelectorAll('.navigation a').forEach(anchor => {
            anchor.addEventListener('click', function(e) {
                e.preventDefault();
                const targetId = this.getAttribute('href');
                const targetElement = document.querySelector(targetId);
                
                window.scrollTo({
                    top: targetElement.offsetTop - 20,
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html> 